<?php
class Quangcao_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    function xoa($id)
        {
            $result=$this->db->delete('quangcao',array('id_quangcao'=>$id));
            return $result;
        }
    function themquangcao($loai,$link,$trangthai,$vitri,$thutu,$nguoitao,$ten_nguoitao,$ngaybatdau,$ngayketthuc)
        {
        	switch ($vitri){
        		case "right":
        			$order = 1;
        			break;
        		case "left":
        			$order = 2;
        			break;
        		case "bottom":
        			$order = 3;
        			break;
        		default:
        			$order = 4;
        			break;
        	}
            $data=array(
            'loai_quangcao'=>$loai,
            'noidung_quangcao'=>$link,
            'trangthai_quangcao'=>$trangthai,
            'vitri_quangcao'=>$order,
            'thutu_quangcao'=>$thutu,
            'datetime_begin'=>$ngaybatdau,
            'datetime_finish'=>$ngayketthuc,
            'nguoidung_first'=>$nguoitao,
            'ten_nguoidung_first'=>$ten_nguoitao
            );
            $result=$this->db->insert('quangcao',$data);
            return $result;
        }
    function sua($id,$nguoisua,$ten_nguoisua)
        {
            $data=array(
            'loai_quangcao'=>$this->loai,
            'noidung_quangcao'=>$this->noidung,
            'trangthai_quangcao'=>$this->trangthai,
            'vitri_quangcao'=>$this->vitri,
            'thutu_quangcao'=>$this->thutu,
            'datetime_begin'=>$this->begin,
            'datetime_finish'=>$this->finish,
            'nguoidung_last'=>$nguoitao,
            'ten_nguoidung_last'=>$ten_nguoitao
            );
            $this->db->where('id_quangcao',$id);
            $result=$this->db->update('quangcao',$data);
            return $result;
        }
    function duyet($id,$trangthai)
        {
            $data=array(
            'trangthai_quangcao'=>$trangthai
            );
            $this->db->where('id_quangcao',$id);
            $result=$this->db->update('quangcao',$data);
            return $result;
        }
}
?>